<?php

use yii\helpers\Html;
use yii\grid\GridView;
use common\models\Order;

/* @var $this yii\web\View */
/* @var $searchModel common\models\OrderSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = 'Orders';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="order-index" style="overflow:auto;">

<!--     <h1><?= Html::encode($this->title) ?></h1> -->
    <?php 
    // echo $this->render('_search', ['model' => $searchModel]); ?>

    <div style="margin-bottom: 10px;">
        开始时间：<input type="date" id="start_time" name="start_time" />&nbsp;&nbsp;&nbsp;
        结束时间：<input type="date" id="end_time" name="end_time" />&nbsp;&nbsp;&nbsp;
        <?= Html::a('导出', 'javascript:ed();', ['class' => 'btn btn-success'])  //Html::a('导出', ['export-data', ['params' => $paramsExcel]], ['class' => 'btn btn-success']) ?>
    </div>

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'tableOptions' => ['class' => 'table table-striped table-bordered','style'=>'width:auto;max-width:none;'],
        'options' => ['class' => 'grid-view','style'=>'overflow:auto'],
        'columns' => [
            //['class' => 'yii\grid\SerialColumn'],

            'id',
            'user_id',
            [
                'attribute' => 'order_status',
                'value' => function ($model, $key, $index, $column) {
                    return Order::itemAlias("order_status", $model->order_status);
                },
                'filter'=>Order::itemAlias("order_status"),
            ],
            [
                'attribute' => 'shipping_status',
                'value' => function ($model, $key, $index, $column) {
                    return Order::itemAlias("shipping_status", $model->shipping_status);
                },
                'filter'=>Order::itemAlias("shipping_status"),
            ],
            [
                'attribute' => 'pay_status',
                'value' => function ($model, $key, $index, $column) {
                    return Order::itemAlias("pay_status", $model->pay_status);
                },
                'filter'=>Order::itemAlias("pay_status"),
            ],
             'product_num',
             'product_fee',
             [
                'attribute' => 'shipping_id',
                'value' => 'shipping.shipping_name',
                'filter'=>Order::ship_list(),
            ],
             'address_id',
             'shipping_fee',
             'order_fee',
             'pay_fee',
             'create_time',

            ['class' => 'yii\grid\ActionColumn', 'template' => '{view}',],
        ],
    ]); ?>
</div>

<script type="text/javascript">
//数据导出
function ed()
{
    var start_time = $.trim($('input[name=start_time]').val());
    var end_time = $.trim($('input[name=end_time]').val());
    var data = '';

    if(start_time){
        data += "?start_time="+start_time;
    }
    
    if(end_time){
        if(start_time){
            data += "&end_time="+end_time;
        }else{
            data += "?end_time="+end_time;
        }
    }

    window.location.href="/order/export"+data;
}
</script>